Technical Q&A

TB 65 - Progress Indicators and SetControl32BitValue (29-November-1999)


Q: I was "slumming" in toolbox land the other day and I needed to use a progress indicator control (CDEF 5), along with SetControl32BitMaximum to set the progress limit and SetControl32BitValue to update my progress. When my progress and progress limit go beyond 65535, weird things happen. What's going on?

A: Support for 32-bit control values is implemented in the control definition, not in the Control Manager itself. If the control definition does not support 32-bit control values, values outside of the range -32768 through 32767 will be truncated using the following algorithm. This is probably not what you were looking for.

sixteenBitValue = (0x00007FFF & value) | ((0x80000000 & value) >> 16);

This raises a number of related questions:

How can I tell whether a control definition supports 32-bit values?

There is no general way of doing this. The only way to know whether it is safe to use 32-bit values with a particular control definition is to ask its author.

Which standard control definitions support 32-bit values?

In Mac OS 8.5 through 9.0, only the scroll bar (CDEFs 1 and 24) and slider (CDEF 3) control definitions support 32-bit values.

How do I support 32-bit values in my control definition?

The first step is to ensure that you call the 32-bit accessors when you need to access the control's value, minimum, and maximum. Obviously, you should do this only if these accessors are available (Mac OS 8.5 or later, or Carbon). Beyond that, it's a simple matter of checking that your implementation handles these large values.

How do I work around this problem for the progress bar control?

If the upper limit of your progress is beyond 32767, the simplest workaround is to set the control's maximum to 32767 and then scale the control value, as shown below. It is often convenient to use floating point arithmetic to avoid overflows.
scaledValue = (unscaledValue / unscaledLimit) * 32767;

Isn't this supposed to be easier?

Don't ask me, I'm just a networking guy. [2409633]

-- Quinn "The Eskimo!"
Worldwide Developer Technical Support

Technical Q&As | Contents
Previous Question | Next Question

To contact us, please use the Contact Us page.